module.exports = {
    ws : WebSocket,
    init (){
        this.ws = new WebSocket("ws://10.4.82.169:8339");
        this.ws.onopen = function (event) {
            console.log("Send Text WS was opened.");
            //this.ws.send(JSON.stringify({type : 0 , data : "hello"}));
        }.bind(this);
        this.ws.onmessage = function (event) {
            console.log(event.data);
            var ret = JSON.parse(event.data);
            switch(ret.type){
                case 0:{break;}
                case 1:{if(this.RevList != undefined) this.RevList(ret.data);break;}
                case 3:{if(this.RevUser != undefined) this.RevUser(ret.data);break;}
            }
        }.bind(this);
        this.ws.onerror = function (event) {
            console.log("Send Text fired an error");
        }.bind(this);
        this.ws.onclose = function (event) {
            console.log("WebSocket instance closed.");
        }.bind(this);
    },
    sendMsg(m_type,m_object){
        this.ws.send(JSON.stringify({type : m_type,data : JSON.stringify(m_object)}));
    },
};